package com.ysqcould.web.controller.Community;


import com.ysqcould.Community.domain.Charity;
import com.ysqcould.Community.service.ICharityService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.message.domain.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 慈航公益Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/Community/charity")
public class CharityController extends BaseController
{
    @Autowired
    private ICharityService charityService;

    /**
     * 查询慈航公益列表
     */
    @PreAuthorize("@ss.hasPermi('Community:charity:list')")
    @GetMapping("/list")
    public TableDataInfo list(Charity charity)
    {
        startPage();
        List<Charity> list = charityService.selectCharityList(charity);
        return getDataTable(list);
    }

    /**
     * 导出慈航公益列表
     */
    @PreAuthorize("@ss.hasPermi('Community:charity:export')")
    @Log(title = "慈航公益", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Charity charity)
    {
        List<Charity> list = charityService.selectCharityList(charity);
        ExcelUtil<Charity> util = new ExcelUtil<Charity>(Charity.class);
        util.exportExcel(response, list, "慈航公益数据");
    }

    /**
     * 获取慈航公益详细信息
     */
    @PreAuthorize("@ss.hasPermi('Community:charity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(charityService.selectCharityById(id));
    }

    /**
     * 新增慈航公益
     */
    @PreAuthorize("@ss.hasPermi('Community:charity:add')")
    @Log(title = "慈航公益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Charity charity)
    {
        charity.setAsId(getUserId());
        return toAjax(charityService.insertCharity(charity));
    }

    /**
     * 修改慈航公益
     */
    @PreAuthorize("@ss.hasPermi('Community:charity:edit')")
    @Log(title = "慈航公益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Charity charity)
    {
        return toAjax(charityService.updateCharity(charity));
    }

    /**
     * 删除慈航公益
     */
    @PreAuthorize("@ss.hasPermi('Community:charity:remove')")
    @Log(title = "慈航公益", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(charityService.deleteCharityByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Charity charity)
    {
        return toAjax(charityService.updateStatus(charity));
    }

    /**
     * 开启置顶
     */
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping("/changeIsCarouselStatus")
    public AjaxResult changeIsCarouselStatus(@RequestBody Charity charity)
    {
        return toAjax(charityService.changeIsCarouselStatus(charity));
    }

    /**
     * 开启进度显示
     */
    @Log(title = "消息通知", businessType = BusinessType.UPDATE)
    @PutMapping("/changeShowStatus")
    public AjaxResult changeShowStatus(@RequestBody Charity charity)
    {
        return toAjax(charityService.changeShowStatus(charity));
    }
}
